// import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
// import Layout from '@/views/Layout'
// import Login from '@/views/login.vue'

// //初始化路由
// export const routes = [
//   {
//     path: '/',
//     redirect: '/login'
//   },
//   {
//     path: '/login',
//     name: 'login',
//     component: Login
//   }
// ]

// /**
//  * 根据用户的权限，所操作的页面和可操作性也不同
//  */
// //准备动态加载的路由
// export const DynamicRoutes = [
//   {
//     path: '/main',
//     component: Layout,
//     name: 'main',
//     meta: {
//       requiresAuth: true,
//       // name: '首页'
//     },
//     children: [

//     ]
//   },
// ]
// const router = createRouter({
//   history: createWebHashHistory(process.env.BASE_URL),
//   routes,
// })

// export default router

import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
// import routes from './routes'
import routes from '@/router/router2'

const router = createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path == '/login') return next()
  const token = sessionStorage.getItem('token')
  if (!token) {
    next('/login')
  } else {
    next()
  }
})

export default router

